using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;

namespace NL.AdreesableAsset
{
    public class AALoader : MonoBehaviour
    {

        public string URL;

        public Transform Parent;

        public float Delay;

        public GameObject LoadedOBJ;

        public UnityEvent<GameObject> OnLoaded;
        // Start is called before the first frame update
        IEnumerator Start()
        {
            yield return new WaitForSeconds(Delay);

            _Load();

        }
        void _Load()
        {
            AA.LOAD<GameObject>(URL, (url,w) =>
            {
                if(w!=null)
                {
                    LoadedOBJ= GameObject.Instantiate<GameObject>(w, Parent);
                    LoadedOBJ.SetActive(true);
                    OnLoaded?.Invoke(LoadedOBJ);
                }
            },gameObject);
        }

    }
}

